package com.yonyou.pmclouds.messagenotice.constructor.impl;

import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.entity.Entity;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.messagenotice.entity.MessageNoticeVO;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import com.yonyou.pmclouds.workConnect.entity.WorkConnectVO;
import com.yonyou.pmclouds.workConnect.service.rmiitf.WorkConnectQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class WorkConnectNoticeConstructor extends AbstractMessageNoticeConstructor {

    private final WorkConnectQuery connectQuery;

    private final ProjectSimpleQuery projectSimpleQuery;

    @Autowired
    public WorkConnectNoticeConstructor(WorkConnectQuery connectQuery, ProjectSimpleQuery projectSimpleQuery) {
        this.connectQuery = connectQuery;
        this.projectSimpleQuery = projectSimpleQuery;
    }


    @Override
    protected MessageNoticeVO[] generateContent(Entity vo) throws BusinessException {
        MessageNoticeVO noticeVO = coverBusinessVOToMessageVO(vo);
        if(noticeVO == null){
            return null;
        }
        // 您下发的工作联系单某某已确认接收
        WorkConnectVO connectVO = connectQuery.selectOne(noticeVO.getRelateKey());
        ProjectVO projectVO = projectSimpleQuery.queryProject(connectVO.getPk_project());

        String messageContent = "您下发的工作联系单" + noticeVO.getCreatorName() + "已确认接收";

        noticeVO.setMessageTitle(projectVO.getSname());
        noticeVO.setMessageReceiver(connectVO.getCreator());
        noticeVO.setPkTenant(connectVO.getPk_tenant());
        noticeVO.setMessageContent(messageContent);
        noticeVO.setRelateType(connectVO.getBill_type());

        return new MessageNoticeVO[]{noticeVO};
    }

    @Override
    public String getRelateType() {
        return BillTypeConst.WORKCONNECT_BILLTYPE;
    }
}
